﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RolePlayingGame
{
    public abstract class PlayerBase : MapObject, ICollidable
    {
        public PlayerBase(Coord startLocation, char symbol)
            : base(startLocation, symbol)
        {
            this.memoryFreed = 0;
            this.level = 1;
            this.health = 300;
        }
        protected int memoryFreed;
        protected int level;
        protected int health;
        protected int armour;
        protected int damage;
        protected int speed;

        public int Health
        {
            get { return this.health; }
        }

        public int Level
        {
            get { return this.level; }
            set 
            {
                this.level = value;
            }
        }
        public int MemoryFreed 
        {
            get { return this.memoryFreed; }
            set { this.memoryFreed = value; }
        }

        public virtual void TakeDamage(int amoutDamage)
        {
            if (amoutDamage <= this.health)
                Disapear();
            else
            {
                this.health -= amoutDamage;
            }
        }

        public virtual void LevelUp(int level)
        {
            if (this.level == level) return; //ensures boost given only when moving up to new level
            this.level = level;
            this.health += level * 100;
            this.damage += level * 25;
            this.speed += level * 25;
            this.armour += level * 25;
        }

        public virtual void GainMF(int memFreed)
        {
            this.memoryFreed += memFreed;
            if (this.memoryFreed <= 100)
            {
                LevelUp(1);
            }
            else if (this.memoryFreed > 100 && this.memoryFreed <=400)
            {
                LevelUp(2);
            }
            else if (this.memoryFreed > 400 && this.memoryFreed <= 800)
            {
                LevelUp(3);
            }
            else if (this.memoryFreed > 800 && this.memoryFreed <= 1600)
            {
                LevelUp(4);
            }
            else if (this.memoryFreed >1600)
            {
                LevelUp(5);
            }
        }

        public virtual void DamageUp(Crossbow weapon)
        {
            this.damage += weapon.UpgardeStrenght;
        }

        public virtual void SpeedUp(Boots boots)
        {
            this.speed += boots.UpgardeStrenght;
        }

        public virtual void ArmorUp(Shield shield)
        {
            this.armour += shield.UpgardeStrenght;
        }

        public virtual Shot Shoot()
        {
            Coord shotLocation = this.Location;
            shotLocation.Y--;
            return new Shot(shotLocation, '|');
        }

        public void CollideWith(MapObject other)
        {
            if (other.GetType() == typeof(EnemyBase))
            {
                
            }
            else if (other.GetType() == typeof(ItemBase))
            {
                if (other.GetType() == typeof(Shield))
                {
                    ArmorUp((Shield)other);
                }
                else if (other.GetType() == typeof(Boots))
                {
                    SpeedUp((Boots)other);
                }
                else if (other.GetType() == typeof(Crossbow))
                {
                    DamageUp((Crossbow)other);
                }
            }
        }


        
    }
}
